package quartz.example.xilou;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

/**
 * Created by yong on 2016/4/19.
 */
public class Main {
    public static void main(String[] args) throws Exception{
        Logger log = LoggerFactory.getLogger(Main.class);
        log.info("------- Initializing -------------------");

        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler sched = factory.getScheduler();

        JobDetail jobDetail = newJob(Job1.class).withIdentity("job1", "group1").build();

        SimpleTrigger trigger = (SimpleTrigger) newTrigger().withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(simpleSchedule().withIntervalInSeconds(1).repeatForever())
                .build();

        sched.scheduleJob(jobDetail, trigger);
        sched.start();
    }
}
